package com.rerun.phone.memberuser;

import com.rerun.common.anno.ResponseExceptionReturn;
import com.rerun.common.bean.Rest;
import com.rerun.common.controller.SuperController;
import com.rerun.entity.JobIntention;
import com.rerun.service.IJobIntentionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 求职意向
 *
 * @author dax.
 * @version v1.0
 * @since 2017 /10/9 10:17
 */
@Api(value = "求职端-个人求职意向", description = "求职端-个人求职意向")
@RestController
@RequestMapping("/memberApi/jobIntention")
public class JobIntentionController extends SuperController {
    @Resource
    private IJobIntentionService iJobIntentionService;

    /**
     * Add job intention rest.
     *
     * @param jobIntention the job intention
     * @return the rest
     */
    @ApiOperation(value = "添加个人求职意向", notes = "添加个人求职意向", httpMethod = "POST")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseExceptionReturn
    public Rest addJobIntention(@ModelAttribute JobIntention jobIntention) {
        jobIntention.setCreateTime(new Date());
        boolean flag = iJobIntentionService.insert(jobIntention);
        return flag ? Rest.ok("添加成功") : Rest.failure("添加失败");
    }

    /**
     * Update job intention rest.
     *
     * @param jobIntention the job intention
     * @return the rest
     */
    @ApiOperation(value = "更新个人求职意向", notes = "更新个人求职意向", httpMethod = "POST")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseExceptionReturn
    public Rest updateJobIntention(@ModelAttribute JobIntention jobIntention) {
        jobIntention.setUpdateTime(new Date());
        boolean flag = iJobIntentionService.updateById(jobIntention);
        return flag ? Rest.ok("更新成功") : Rest.failure("更新失败");
    }

    /**
     * Gets by member id.
     *
     * @param memberId the member id
     * @return the by member id
     */
    @ApiOperation(value = "求职意向", notes = "根据用户id获取其求职意向", httpMethod = "GET")
    @RequestMapping(value = "/get/{memberId}", method = RequestMethod.GET)
    @ResponseExceptionReturn
    public Rest getByMemberId(@ApiParam(required = true, name = "memberId", value = "用户id") @PathVariable("memberId") String memberId) {
        JobIntention jobIntention = iJobIntentionService.selectByMemberId(memberId);
        return Rest.okData(jobIntention);
    }
}
